package com.atguigu.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
@Component
public class FeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        ServletRequestAttributes requestAttributes=(ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        if(requestAttributes!=null){
            //在这里相当于是shop-web的request
            HttpServletRequest request = requestAttributes.getRequest();
            requestTemplate.header("userTempId",request.getHeader("userTempId"));
            requestTemplate.header("userId",request.getHeader("userId"));
        }
    }
}
